package com.ruibang.glass.file.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruibang.glass.file.domain.req.DirInfo;
import com.ruibang.glass.file.domain.req.FolderInfoReq;
import com.ruibang.glass.file.entity.FolderInfo;
import com.ruibang.glass.file.service.FolderInfoService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;


/**
 * <p>
 * 文件夹信息 前端控制器
 * </p>
 *
 * @author songJinKang
 * @since 2024-04-15
 */
@Slf4j
@RestController
@Validated
@RequestMapping("/api/glass/folder")
@Api(value = "文件夹信息控制器", tags = {"文件夹信息接口"})
public class FolderInfoController {

    @Autowired
    private FolderInfoService folderInfoService;

    @PostMapping("/getNextDirInfo")
    @ApiOperation(value = "获取下一级文件夹信息", notes = "获取下一级文件夹信息")
    public ResultBody<Page<FolderInfo>> getNextDirInfo(@RequestBody @Valid FolderInfoReq folderInfoReq) {
        return ResultBody.success(folderInfoService.getNextDirInfo(folderInfoReq));
    }

    @PostMapping("/upload")
    @ApiOperation(value = "上传", notes = "上传")
    public ResultBody upload(@RequestBody @Valid List<FolderInfo> folderInfos) {
        folderInfoService.upload(folderInfos);
        return ResultBody.success();
    }

    @PostMapping("/createDir")
    @ApiOperation(value = "创建文件夹", notes = "创建文件夹")
    public ResultBody createDir(@RequestBody @Valid DirInfo dirInfo) {
        folderInfoService.createDir(dirInfo);
        return ResultBody.success();
    }

    @DeleteMapping("/deleteById/{id}")
    @ApiOperation(value = "删除文件", notes = "删除文件")
    public ResultBody deleteById(@PathVariable String id) {
        folderInfoService.deleteById(id);
        return ResultBody.success();
    }
}
